<template>
    <div class="app-container">
      <el-radio-group v-model="queryParams.status" @change="getList" style="margin-bottom: 30px;">
        <el-radio-button v-for="(item,index) in tabList" :key="index" :label="item.value">{{item.label}}</el-radio-button>
      </el-radio-group>
      <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch">
        <el-form-item label="手机号" prop="phone">
          <el-input
             v-model="queryParams.phone"
             placeholder="请输入手机号"
             clearable
             @keyup.enter="handleQuery"
          />
        </el-form-item>
        <el-form-item label="车牌号" prop="plateNumber">
          <el-input
              v-model="queryParams.plateNumber"
              placeholder="请输入车牌号"
              clearable
              @keyup.enter="handleQuery"
          />
        </el-form-item>
        <el-form-item label="用户名称" prop="nickName">
          <el-input
              v-model="queryParams.nickName"
              placeholder="请输入用户名称"
              clearable
              @keyup.enter="handleQuery"
          />
        </el-form-item>
        <el-form-item label="创建时间" prop="dateRange">
          <el-date-picker
            v-model="queryParams.dateRange"
            type="datetimerange"
            range-separator="-"
            start-placeholder="开始日期"
            value-format="yyyy-MM-dd HH:mm:ss"
            style="width:333px;"
            :default-time="['00:00:00','23:59:59']"
            end-placeholder="结束日期">
          </el-date-picker>
        </el-form-item>
        <!-- <el-form-item label="状态" prop="status">
          <el-select
            v-model="queryParams.status"
            placeholder="请选择状态"
            clearable
            style="width: 240px"
          >
            <el-option
              v-for="dict in dict.type.car_status"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value"
            />
          </el-select>
        </el-form-item> -->
        <el-form-item>
          <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
          <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
        </el-form-item>
      </el-form>
      <el-row :gutter="10" class="mb8">
        <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
      </el-row>

      <!-- 表格数据 -->
      <el-table v-loading="loading" :data="list" >
        <el-table-column label="用户名称" align="center" prop="nickName"/>
        <el-table-column label="手机号" align="center" prop="phone"/>
        <el-table-column label="车牌号" align="center" prop="plateNumber"/>
        <el-table-column label="状态" align="center" prop="status">
          <template slot-scope="{row}">
            <dict-tag :options="dict.type.car_status" :value="row.status" />
          </template>
        </el-table-column>
        <el-table-column label="提交认证时间" align="center" prop="applyAuthTime"/>
        <el-table-column label="审核时间" align="center" prop="verifyAuthTime"/>
        <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
          <template slot-scope="{row}">
            <el-button type="text" v-if="row.status == 2" @click="handleExam(row,1)"
              v-hasPermi="['system:eaVehicle:verify']">审核通过
            </el-button>
            <el-button type="text" v-if="row.status == 2" @click="handleExam(row,2)"
              v-hasPermi="['system:eaVehicle:verify']">审核驳回
            </el-button>
            <el-button type="text" icon="el-icon-view" @click="handleUpdate(row)"
              v-hasPermi="['system:eaVehicle:query']">查看详情
            </el-button>
          </template>
        </el-table-column>
      </el-table>

      <pagination
        v-show="total>0"
        :total="total"
        :page.sync="queryParams.pageNum"
        :limit.sync="queryParams.pageSize"
        @pagination="getList"
      />

      <!-- 添加或修改计费规则对话框 -->
      <el-dialog :title="title" :visible.sync="open" width="70%" append-to-body>
        <el-form ref="formRef" :model="form"  label-width="130px">
          <el-row>
            <el-col :span="12">
              <el-form-item label="用户ID">
                <div class="diy-block-box diy-h-10 diy-leading-10 diy-text-sm">
                  {{ form.userid || '' }}
                </div>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="vin码">
                <div class="diy-block-box diy-h-10 diy-leading-10 diy-text-sm">
                  {{ form.vin || '' }}
                </div>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="手机号">
                <div class="diy-block-box diy-h-10 diy-leading-10 diy-text-sm">
                  {{ form.phone || '' }}
                </div>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="车牌号">
                <div class="diy-block-box diy-h-10 diy-leading-10 diy-text-sm">
                  {{ form.plateNumber || '' }}
                </div>
              </el-form-item>
            </el-col>
            <el-col :span="24" v-if="form.licenseImgPath">
              <el-form-item label="行驶证图片">
                <el-image
                  v-if="form.licenseImgPath"
                  style="width: 100px; height: 100px"
                  :src="form.licenseImgPath"
                  :preview-src-list="[form.licenseImgPath]">
                </el-image>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="即插即充状态">
                <div class="diy-block-box diy-h-10 diy-leading-10 diy-text-sm">
                  <dict-tag :options="dict.type.car_plugcharge_status" :value="form.plugChargeStatus"/>
                </div>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="开通即插即充时间">
                <div class="diy-block-box diy-h-10 diy-leading-10 diy-text-sm">
                  {{ form.applyPlugChargeTime || '' }}
                </div>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="状态">
                <div class="diy-block-box diy-h-10 diy-leading-10 diy-text-sm">
                  <dict-tag :options="dict.type.car_plugcharge_status" :value="form.plugChargeStatus"/>
                </div>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="审核时间">
                <div class="diy-block-box diy-h-10 diy-leading-10 diy-text-sm">
                  {{ form.verifyAuthTime || '' }}
                </div>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="提交认证时间">
                <div class="diy-block-box diy-h-10 diy-leading-10 diy-text-sm">
                  {{ form.applyAuthTime || '' }}
                </div>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="创建时间">
                <div class="diy-block-box diy-h-10 diy-leading-10 diy-text-sm">
                  {{ form.createTime || '' }}
                </div>
              </el-form-item>
            </el-col>
          </el-row>
        </el-form>
        <div slot="footer" class="dialog-footer">
          <!-- <el-button type="primary" @click="submitForm">确 定</el-button> -->
          <el-button @click="cancel">取 消</el-button>
        </div>
      </el-dialog>
    </div>
</template>

<script>
import * as api from "@/api/station/vehicleManage";
import {getAllOperator} from "@/api/station/billing_rules";
export default {
  name: "VehicleManage",
  dicts: ['car_status','car_plugcharge_status'],
  components: {  },
  data() {
    return {
      tabList:[
        {label:'已校验车辆',value:1},{label:'待审核车辆',value:2},
        {label:'审核失败',value:4},{label:'已认证车辆',value:3},
      ],
      form:{},
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      queryParams: {// 查询参数
        pageNum: 1,
        pageSize: 10,
        status:2,
        phone:null,
        plateNumber:null,
        nickName:null,
        dateRange:[],
      },
      // 总条数
      total: 0,
      rules: {},
      operatorOptions:[],//所属运营商
      list:[],//页面数据
    };
  },
  created() {
    this.getList()
  },
  methods: {
    getList() {
      this.loading = true;
      let queryParams = {...this.queryParams}
      let dateRange = queryParams.dateRange || []
      if( dateRange.length ) {
        queryParams.startTime = dateRange[0]
        queryParams.endTime = dateRange[1]
      }
      delete queryParams.dateRange
      api.listEaVehicle(queryParams).then(response => {
        this.list = response.rows || [];
        this.total = response.total || 0;
        this.loading = false;
      });
    },
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id);
      this.single = selection.length != 1;
      this.multiple = !selection.length;
    },
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids;
      this.open = true;
      this.title = "查看详情";
      api.getEaVehicle(id).then(response => {
        let data = response.data || {}
        this.form = {...data};
      });
    },
    submitForm() {
      this.$refs["formRef"].validate(valid => {
        if (valid) {
          if (this.form.id != undefined) {
            api.updateTag(this.form).then(response => {
                this.$modal.msgSuccess("修改成功")
                this.open = false;
                this.getList();
            });
          } else {
            api.addTag(this.form).then(response => {
                this.$modal.msgSuccess("新增成功")
                this.open = false;
                this.getList()
            });
          }
        }
      });
    },
    cancel() {
      this.open = false;
      this.reset();
    },
    handleExam(row,type) {//删除
      const del_ids = row.id
      let apis = type == 2 ? api.verifyFail : api.verifySuccess
      this.$modal.confirm('是否确认删除该数据项？').then(function() {
        return apis(del_ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("操作成功");
      }).catch(() => {});
    },
    // 表单重置
    reset() {
      this.form = {periodPriceList:[{}]};
      this.resetForm("formRef");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.dateRange = [];
      this.resetForm("queryForm");
      this.handleQuery();
    },
  }
};
</script>
<style>
  .diy-block-box{
    border-radius: 4px;padding: 0 15px;box-sizing: border-box;
    border: 1px solid #dfdfdf;
  }
</style>
